﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Course2
{
    /// <summary>
    /// 学习linq和，实现扩展linq
    /// </summary>
    internal class Example4
    {
        public void Test()
        {
            var list = new List<int>()
            {
                1,
                2,
                3,
                4,
                5,
                6,
            };
            var list2 = list.Where(a => a > 3);
        }

        /// <summary>
        /// 了解yield代码生成器（优化）
        ///     代码只会在迭代的时候执行
        /// </summary>
        /// <returns></returns>
        public IEnumerable<int> GetAsync()
        {
            var list = new int[] { 12, 45, 45, 788, 74, 1, 2, 44 };
            foreach (var item in list)
            {
                if (item%2==0)
                {
                    yield return item;
                }
            }
        }
    }
}
